package com.ymtms.applicationsystem.controller;

import com.ymtms.applicationsystem.pojo.Wage;
import com.ymtms.applicationsystem.pojo.WageDel;
import com.ymtms.applicationsystem.pojo.WageCode;
import com.ymtms.applicationsystem.service.WageService;
import com.ymtms.applicationsystem.vo.RequestBean;
import com.ymtms.applicationsystem.vo.Result;
import com.ymtms.applicationsystem.vo.ResultUtil;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.validation.Valid;

/**
 * @auther: autumn-luo
 * @description:
 * @createTime: 2019-10-29 10:50
 */
@Controller
@Log4j2
@CrossOrigin
public class WageController {

    @Autowired
    WageService wageService;


    /*
     * @createTime 2019-10-29 12:15
     * @author autumn-luo
     * @param: requestBean
     * @param: empWageSeekInfo
     * @return:
     * @description: 工资的分页查询
     */
    @RequestMapping("/wageAll")
    @ResponseBody
    public ResultUtil wageAll(RequestBean requestBean,
                              @RequestParam(value = "empWageSeekInfo", required = false) String empWageSeekInfo) {
        Result<Wage> wageAll = wageService.wageAll(requestBean, empWageSeekInfo);
        return ResultUtil.success(wageAll);
    }

    /*
     * @createTime 2019-10-29 14:16
     * @author autumn-luo
     * @param: wageDel
     * @return:
     * @description: 工资条软删除
     */
    @RequestMapping("/wageDel")
    @ResponseBody
    public ResultUtil wageDel(@Valid WageDel wageDel) {
        wageService.wageDel(wageDel.getWageDelId());
        return ResultUtil.success();
    }

    /*
     * @createTime 2019-10-29 15:29
     * @author autumn-luo
     * @param: wage
     * @return:
     * @description:  工资条更新
     */
    @RequestMapping("/wageUpdate")
    @ResponseBody
    public ResultUtil wageUpdate(@Valid Wage wage) {
        wageService.wageUpdate(wage);
        return ResultUtil.success();
    }

    /*
     * @createTime 2019-10-29 16:57
     * @author autumn-luo
     * @param: wage
     * @return:
     * @description: 工资条插入
     */
    @RequestMapping("/wageAdd")
    @ResponseBody
    public ResultUtil wageAdd(@Valid Wage wage) {
        wageService.wageAdd(wage);
        return ResultUtil.success();
    }

    @RequestMapping("/wageNameByCode")
    @ResponseBody
    public ResultUtil wageNameByCode(@Valid WageCode wage) {
        String wageName = wageService.wageNameByCode(wage.getEmployeeCode());
        return ResultUtil.success(wageName);
    }
}
